﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogisticsBLL;
using Model;
using System.Data.SqlClient;

namespace WebLosgic.CapacityTruck
{
    public partial class CapacityTrucks : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int TeamID = Convert.ToInt32(Request.QueryString["Tid"]);
                if (TeamID != 0)
                {
                    ddlTeam.SelectedValue = TeamID.ToString();
                }
                ddlTeamName();
                ddlType();
                BindTrucklist();
            }
        }

        public void BindTrucklist()
        {
           

            CarrierBLL car = new CarrierBLL();
            Trucks tus = new Trucks();
            tus.TeamID = Convert.ToInt32(ddlTeam.SelectedValue);
            tus.Number = TxtNumber.Text.Trim();
            tus.State = Convert.ToInt32(ddlState.SelectedValue);
            tus.Type = ddlTruckType.SelectedValue;

            tus.pageIndex = AspNetPagerTool.CurrentPageIndex;
            tus.pageSize = AspNetPagerTool.PageSize;
            int resout;
            List<Trucks> tru = car.Bindtruck(tus,out resout);
            RptBindDrive.DataSource = tru;
            AspNetPagerTool.RecordCount = resout;
            RptBindDrive.DataBind();
        }


        public void ddlTeamName()
        {
            CarrierBLL car = new CarrierBLL();
            ddlTeam.DataSource = car.ddlTeamName();
            ddlTeam.DataTextField = "TeamName";
            ddlTeam.DataValueField = "TeamID";
            ddlTeam.DataBind();
            ddlTeam.Items.Insert(0, new ListItem("--全部--", "0"));
        }

        public void ddlType()
        {
            CarrierBLL car = new CarrierBLL();
            ddlTruckType.DataSource = car.ddlType();
            ddlTruckType.DataTextField = "Type";
            ddlTruckType.DataValueField = "Type";
            ddlTruckType.DataBind();
            ddlTruckType.Items.Insert(0, new ListItem("--全部--", " "));
        }

        protected void Btnselect_Click(object sender, EventArgs e)
        {
            CarrierBLL car = new CarrierBLL();
            Trucks tus = new Trucks();
            tus.TeamID =Convert.ToInt32(ddlTeam.SelectedValue);
            tus.Number = TxtNumber.Text;
            tus.State = Convert.ToInt32(ddlState.SelectedValue);
            tus.Type = ddlTruckType.SelectedValue;
            tus.pageIndex = AspNetPagerTool.CurrentPageIndex;
            tus.pageSize = AspNetPagerTool.PageSize;
            int recout = 0;
            List<Trucks> tru = car.Bindtruck(tus,out recout);
            RptBindDrive.DataSource = tru;
            AspNetPagerTool.RecordCount = recout;
            RptBindDrive.DataBind();
        }

        protected void AspNetPagerTool_PageChanged(object sender, EventArgs e)
        {
            BindTrucklist();
        }

       
    }
}